package com.example.backend.mapper;

import com.example.backend.domain.entity.*;
import com.example.backend.dto.*;

public class SimpleMappers {
    public static UserDto toUserDto(User user) {
        if (user == null) return null;
        UserDto dto = new UserDto();
        dto.setId(user.getId());
        dto.setUsername(user.getUsername());
        dto.setFullName(user.getFullName());
        dto.setEmail(user.getEmail());
        dto.setPhone(user.getPhone());
        dto.setAvatarUrl(user.getAvatarUrl());
        dto.setDepartment(user.getDepartment());
        dto.setPosition(user.getPosition());
        dto.setEmployeeId(user.getEmployeeId());
        dto.setRole(user.getRole() != null ? user.getRole().name().toLowerCase() : null);
        dto.setStatus(user.getStatus() != null ? user.getStatus().name() : null);
        dto.setLastLoginAt(user.getLastLoginAt());
        dto.setLoginCount(user.getLoginCount());
        dto.setCreatedAt(user.getCreatedAt());
        dto.setUpdatedAt(user.getUpdatedAt());
        return dto;
    }

    public static TicketDto toTicketDto(Ticket ticket) {
        if (ticket == null) return null;
        TicketDto dto = new TicketDto();
        dto.setId(ticket.getId());
        dto.setTicketNumber(ticket.getTicketNumber());
        dto.setTitle(ticket.getTitle());
        dto.setDescription(ticket.getDescription());
        dto.setDescriptionDetail(ticket.getDescriptionDetail());
        
        // 分类信息
        dto.setCategoryId(ticket.getCategory() != null ? ticket.getCategory().getId() : null);
        dto.setCategoryName(ticket.getCategory() != null ? ticket.getCategory().getCategoryName() : null);
        
        // 枚举字段
        dto.setPriority(ticket.getPriority());
        dto.setStatus(ticket.getStatus());
        dto.setSource(ticket.getSource());
        
        // 用户信息
        dto.setCustomerId(ticket.getCustomer() != null ? ticket.getCustomer().getId() : null);
        dto.setCustomerName(ticket.getCustomer() != null ? ticket.getCustomer().getFullName() : null);
        dto.setCustomerEmail(ticket.getCustomer() != null ? ticket.getCustomer().getEmail() : null);
        
        dto.setAssignedToId(ticket.getAssignedTo() != null ? ticket.getAssignedTo().getId() : null);
        dto.setAssignedToName(ticket.getAssignedTo() != null ? ticket.getAssignedTo().getFullName() : null);
        dto.setAssignedToEmail(ticket.getAssignedTo() != null ? ticket.getAssignedTo().getEmail() : null);
        
        dto.setCreatedById(ticket.getCreatedBy() != null ? ticket.getCreatedBy().getId() : null);
        dto.setCreatedByName(ticket.getCreatedBy() != null ? ticket.getCreatedBy().getFullName() : null);
        
        dto.setResolvedById(ticket.getResolvedBy() != null ? ticket.getResolvedBy().getId() : null);
        dto.setResolvedByName(ticket.getResolvedBy() != null ? ticket.getResolvedBy().getFullName() : null);
        
        dto.setClosedById(ticket.getClosedBy() != null ? ticket.getClosedBy().getId() : null);
        dto.setClosedByName(ticket.getClosedBy() != null ? ticket.getClosedBy().getFullName() : null);
        
        // 时间信息
        dto.setDueDate(ticket.getDueDate());
        dto.setResolvedAt(ticket.getResolvedAt());
        dto.setClosedAt(ticket.getClosedAt());
        dto.setCreatedAt(ticket.getCreatedAt());
        dto.setUpdatedAt(ticket.getUpdatedAt());
        
        // 工时信息
        dto.setEstimatedHours(ticket.getEstimatedHours());
        dto.setActualHours(ticket.getActualHours());
        
        // 满意度信息
        dto.setSatisfactionScore(ticket.getSatisfactionScore());
        dto.setSatisfactionComment(ticket.getSatisfactionComment());
        
        // 其他信息
        dto.setInternalNotes(ticket.getInternalNotes());
        dto.setIsPublic(ticket.getIsPublic());
        dto.setIsEscalated(ticket.getIsEscalated());
        dto.setEscalationReason(ticket.getEscalationReason());
        
        return dto;
    }

    public static FeedbackDto toFeedbackDto(Feedback feedback) {
        if (feedback == null) return null;
        FeedbackDto dto = new FeedbackDto();
        dto.setId(feedback.getId());
        dto.setTicketId(feedback.getTicket() != null ? feedback.getTicket().getId() : null);
        dto.setAuthorId(feedback.getAuthor() != null ? feedback.getAuthor().getId() : null);
        dto.setContent(feedback.getContent());
        dto.setRating(feedback.getRating());
        dto.setCreatedAt(feedback.getCreatedAt());
        return dto;
    }

    public static CommentDto toCommentDto(Comment comment) {
        if (comment == null) return null;
        CommentDto dto = new CommentDto();
        dto.setId(comment.getId());
        dto.setTicketId(comment.getTicket() != null ? comment.getTicket().getId() : null);
        dto.setAuthorId(comment.getAuthor() != null ? comment.getAuthor().getId() : null);
        dto.setContent(comment.getContent());
        dto.setCreatedAt(comment.getCreatedAt());
        return dto;
    }
}


